package mk.jug.academy.preconditions;

import mk.jug.academy.exception.BusinessException;
import mk.jug.academy.model.Lecturer;
import mk.jug.academy.model.Student;
import mk.jug.academy.model.StudentReview;
import mk.jug.academy.model.StudentReviewStatus;
import mk.jug.academy.service.StudentReviewService;

import org.springframework.util.Assert;


/**
 * Class separating the concerns of checking preconditions for
 * used in {@link StudentReviewService}.
 * 
 * It is usually a Precondition <-> Service pair.
 *
 * @author Ice.Penov
 */
public final class StudentReviewPreconditions {
	
	/** No instantiation. Static usage only. */
	private StudentReviewPreconditions() {;}
	
	public static void startReview(Student student, Lecturer lecturer, StudentReview studentReview) {
		Assert.isNull(studentReview.getId(), PreconditionExceptions.ID_SHOULD_BE_NULL);
		Assert.notNull(student.getId(), PreconditionExceptions.ID_IS_NULL);
		Assert.notNull(lecturer.getId(), PreconditionExceptions.ID_IS_NULL);
	}
	
	public static void continueReview(StudentReview studentReview) {
		Assert.notNull(studentReview.getId(), PreconditionExceptions.ID_IS_NULL);
		if (!studentReview.getStatus().equals(StudentReviewStatus.BEING_DEFINED)) {
			throw new BusinessException(ErrorCodes.ERROR_STUDENT_REVIEW_BEING_DEFINED_STATE);
		}
	}

	public static void completeReview(StudentReview studentReview) {
		Assert.notNull(studentReview.getId(), PreconditionExceptions.ID_IS_NULL);
		if (!studentReview.getStatus().equals(StudentReviewStatus.BEING_DEFINED)) {
			throw new BusinessException(ErrorCodes.ERROR_STUDENT_REVIEW_BEING_DEFINED_STATE);
		}
	}
	
	public static void deleteReview(StudentReview studentReview) {
		Assert.notNull(studentReview.getId(), PreconditionExceptions.ID_IS_NULL);
	}	

}